﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.DependencyInjection;
using Swimj.Core.Securities;

namespace Swimj.AspNetCore.Infrastructure.Auth
{
    public static class ServiceCollectionExtension
    {
        public static IServiceCollection AddCurrentUser(this IServiceCollection services) =>
        services
            .AddScoped<SecurityMiddleware>()
            .AddScoped<ISecurityUser, CurrentUser>()
            .AddScoped(sp => (ICurrentUserInitializer)sp.GetRequiredService<ISecurityUser>());

        public static IServiceCollection AddPermissions(this IServiceCollection services) =>
            services
                .AddScoped<IAuthorizationHandler, PermissionAuthorizationHandler>();

    }
}
